package cmd.commands;

import java.util.logging.Level;

import platform.PlatformObjectFactory;

import model.Player;
import model.Preference;
import util.EmailSending;
import util.LoggingUtils;
import util.PlayerUtilities;


public class DayScheduleCommand extends Command {
	public DayScheduleCommand(Command c) {
		super(c.command, c.parameters);
	}

	@Override
	public boolean execute() {

		if(this.parameters==null || this.parameters.length==0) {
			return false;
		}
		else 
		{
			try
			{
				Preference.getInstance().setScheduleday(Integer.parseInt(this.parameters[0]));
				Preference.getInstance().save();
				Player.getInstance().save();
				LoggingUtils.log(Level.SEVERE, " Changing the restart schedule by "+this.parameters[0]);
				PlayerUtilities.saveJsonToFile("RESTART_SCHEDULE_TIME",Integer.parseInt(this.parameters[0]));
				PlatformObjectFactory.getInstance().getCommandExecutor().restartPlayer();
			}
			catch(Exception e)
			{
				LoggingUtils.log(Level.SEVERE, " at DayScheduleCommand.execute() Unable to change player restart schedule day \n"+EmailSending.FormatException(e));
			}
		}
		return true;
	}
}
